package com.my.mymafengwo.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import java.util.List;

/**
 * ***********************************************
 * author:wgh
 * time:2015/12/4 11:55
 * copyright:
 * name:
 * step:
 * ***********************************************
 */
public class StoreCityPagerAdapter extends PagerAdapter {

    private Context context;
    private List<GridView> data;

    public StoreCityPagerAdapter(Context context) {
        this.context = context;
    }


    @Override
    public int getCount() {
        return data==null?0:data.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = data.get(position);
        if (view.getParent() != null) {
            container.removeView(view);
        }
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(data.get(position));
    }

    public void setData(List<GridView> data) {
        this.data = data;
    }

}
